package com.tool.emulator.apple2.runtime;

import com.tool.emulator.common.VirtualDevice;
import com.tool.emulator.mos6502.Registers;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class EmuState {

	private Map<String, byte[]> deviceByteStateMap = new ConcurrentHashMap<>();
	private Map<String, Registers> registersStateMap = new ConcurrentHashMap<>();
	private Map<String, VirtualDeviceState> virtualDeviceStateMap = new ConcurrentHashMap<>();

	public Registers getDeviceRegistersState(VirtualDevice virtualDevice) {
		Registers res = registersStateMap.get(virtualDevice.getName().toUpperCase());
		return res;
	}

	public void putDeviceRegistersState(VirtualDevice virtualDevice, Registers res) {
		registersStateMap.put(virtualDevice.getName().toUpperCase(), res);
	}

	public byte[] getDeviceByteState(VirtualDevice virtualDevice) {
		byte[] bs = deviceByteStateMap.get(virtualDevice.getName().toUpperCase());
		return bs;
	}

	public void putDeviceByteState(VirtualDevice virtualDevice, byte[] bytes) {
		deviceByteStateMap.put(virtualDevice.getName().toUpperCase(), bytes);
	}

	public VirtualDeviceState getVirtualDeviceState(VirtualDevice virtualDevice) {
		VirtualDeviceState vds = virtualDeviceStateMap.get(virtualDevice.getName().toUpperCase());
		return vds;
	}

	public void putVirtualDeviceState(VirtualDevice virtualDevice, VirtualDeviceState virtualDeviceState) {
		virtualDeviceStateMap.put(virtualDevice.getName().toUpperCase(), virtualDeviceState);
	}

	public synchronized void clear() {
		this.deviceByteStateMap.clear();
		this.registersStateMap.clear();
		this.virtualDeviceStateMap.clear();

	}

}
